//字符串转ArrayBuffer
export const str_to_ab = (str) => {  
  var buf = new ArrayBuffer(str.length);
  var bufView = new Uint8Array(buf);
  for (var i = 0, strLen = str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return buf;
}
//ArrayBuffer转字符串
export const ab_to_str = (res) => {
  var buffer = res.message;
  var dataview = new DataView(buffer);
  var ints = new Uint8Array(buffer.byteLength);
  var str = '';
  for (var i = 0; i < ints.length; i++) {
    str += String.fromCharCode(dataview.getUint8(i));
  }
  return str;
}